<template>
	<div class="modal fade" tabindex="-1" role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title">{{operationName}}用户</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal">
				
									
						<div class="form-group">
							<label class="col-sm-2 control-label">名称</label>
							<div class="col-sm-10">
								<input class="form-control" v-model="role.name" >
							</div>
						</div>
						
	
						<div class="form-group">
							<label class="col-sm-2 control-label">描述</label>
							<div class="col-sm-10">
								<input class="form-control" v-model="role.descript" >
							</div>
						</div>

					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" @click="save">{{operationName}}</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
</template>

<script>
export default{
	data() {
		return {
		}
	},
	props: {
		role: Object
	},

	computed: {
		operationName() {
			return this.role.id ? "修改" : "新增"
		}
	},

	methods: {
		save() {
			if(!this.$global.validator.require(this.role.name, '名称')) return

			let url = process.env.VUE_APP_SERVER + 'system/admin/role/save'
			this.$axios.post(url, this.role)
				.then(res => {
					if(res.data.status === 1) {
						this.$toast(this.operationName + '角色成功', this.$global.toast.success)
						$('#save-modal').modal('hide')
						this.$parent.list(1)
					}else {
						this.$toast(res.data.msg, this.$global.toast.fail)
					}
				})
		},

	}
}	
</script>

<style>
</style>
